<?php

namespace App\Http\Controllers\Admins;

use App\Http\Controllers\AdminController;
use App\Models\AppUser;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class User extends AdminController
{
    public function list(Request $request)
    {
        $elem = AppUser::latest();

        $data = $elem->paginate($request->input('limit',10));

        return $this->ReturnPage($data);
    }

    public function listPost(Request $request)
    {
        $validator = Validator::make($post = $request->all(),[
            'id'    => 'required|integer',
        ]);

        if ($validator->fails()){

            return $this->ReturnFailed(1,$validator->errors());
        }

        AppUser::updateOrCreate(['id'=>$post['id']],$post);

        return $this->ReturnSuccessInfo();
    }

}
